var express = require('express');
var router = express.Router();
var session = require('express-session');
var moment = require('moment');

var db = require('./../../utils/db.js');


//获取项目历史版本列表页面
router.get("/listAll", function (req, res, next) {
    var projectId = req.session.projectId;
    var versionSql = "select * from version_base as v where v.project_base_id=" + projectId + "";
    db.query(versionSql, function (err, datas) {
        if (datas && datas.length >= 0) {
            res.render('process/historyVersion/index', {
                versionList: datas
            });
        } else {
            res.render('error', {
                message: err.message,
                error: err
            });
        }

    })
});

/**
 * 直接返回版本列表
 */
router.get("/datagrid", function (req, res, next) {
    var projectId = req.query.projectId;
    var versionSql = "select * from version_base as v where v.project_base_id=" + projectId + "";
    db.query(versionSql, function (err, rows) {
        if (rows && rows.length >= 0) {
            res.json({
                errcode: 0,
                message: '获取版本列表成功',
                data: rows,
                timestamp: moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
            });
        } else {
            res.json({
                message: '获取版本列表失败',
                errcode: 1,
                detail: err.message,
                timestamp: moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
            });
        }

    })
});


module.exports = router;